package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 质量检查状态枚举
 *
 * <p>管理质量检查的状态流程，包括待检查、检查中、已完成、失败、审核中等状态</p>
 *
 * @author System
 * @version 1.0.0
 */
public enum QualityCheckStatus implements BaseEnum {

    /** 待检查 */
    PENDING("PENDING", "待检查"),

    /** 检查中 */
    IN_PROGRESS("IN_PROGRESS", "检查中"),

    /** 已完成 */
    COMPLETED("COMPLETED", "已完成"),

    /** 失败 */
    FAILED("FAILED", "失败"),

    /** 审核中 */
    REVIEWING("REVIEWING", "审核中");

    private final String code;
    private final String description;

    QualityCheckStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return description;
    }

    public static QualityCheckStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return PENDING;
        }

        for (QualityCheckStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return PENDING;
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值，PENDING如果未找到
     */
    public static QualityCheckStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return PENDING;
        }

        for (QualityCheckStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        return PENDING;
    }
}